<template>
  <div v-if="row.actions.length > 2">
    <a
      @click="handleClickMore(row.actions[0].name, row)"
      v-if="showBtn(row.actions[0].label)"
      >{{ row.actions ? row.actions[0].label : "" }}</a
    >
    <Divider type="vertical" />
    <Dropdown @on-click="(name) => handleClickMore(name, row)" transfer>
      <a
        >更多
        <Icon type="ios-arrow-down" />
      </a>
      <DropdownMenu slot="list">
        <template v-for="(item, i) in row.actions.slice(1)">
          <DropdownItem :key="i" :name="item.name" v-if="showBtn(item.label)"
            >{{ item.label }}
          </DropdownItem>
        </template>
      </DropdownMenu>
    </Dropdown>
  </div>
  <div v-else>
    <a
      v-if="row.actions && showBtn(row.actions[0].label)"
      @click="handleClickMore(row.actions[0].name, row)"
      >{{ row.actions[0].label }}</a
    >
    <Divider v-if="row.actions && row.actions.length > 1" type="vertical" />
    <a
      v-if="
        row.actions && row.actions.length > 1 && showBtn(row.actions[1].label)
      "
      @click="handleClickMore(row.actions[1].name, row)"
      >{{ row.actions[1].label }}</a
    >
  </div>
</template>
<script>
import dynamictableactions from '@/mixins/dynamictableactions'; // 混入通用代码
import { ApiRequest } from '@api/basePage';
import { mapGetters } from 'vuex';
import { getBtnsId } from '@/libs/btnsPermission';
export default {
  mixins: [dynamictableactions],
  data () {
    return {
      deleteUuids: [],
      actions: []
    };
  },
  created () {},
  computed: {
    ...mapGetters('permissions/systemBtns', ['showBtn'])
  },
  methods: {
    handleClickMore (name, row) {
      if (name === 'Edit') {
        let jumpPath = this.basePath + 'Edit';
        this.$router.push({
          path: jumpPath,
          query: {
            uuid: row.uuid
          }
        });
      } else if (name === 'Delete') {
        this.$Modal.confirm({
          title: '删除操作',
          content: '确定删除此数据吗？',
          onOk: () => {
            let curBtnId = getBtnsId('删除');
            sessionStorage.setItem('buttonId', curBtnId);
            let data = {
              uuids: row.uuid
            };
            // 开始请求商品列表
            ApiRequest(
              this.requestApi.delTableList.url,
              this.requestApi.delTableList.type,
              data,
              true
            ).then((res) => {
              if (res.retStatus === '1') {
                this.$Message.success('删除成功');
                this.actionsChange();
              }
            });
          }
        });
      } else if (name === 'View') {
        let jumpPath = this.basePath + 'View';
        /* this.$router.push({
          path: jumpPath,
          query: {
            uuid: row.uuid
          }
        }); */
        const { href } = this.$router.resolve({ path: jumpPath, query: { uuid: row.uuid } });
        window.open(href, '_blank');
      } else if (name == 'ReAudit') {
        this.$router.push({
          name: 'brandEdit',
          query: { pageType: 'reSubmit', uuid: row.uuid, }
        });
        // this.$Modal.confirm({
        // 	title: '重新提交审核',
        // 	content: '确定重新审核此数据吗？',
        // 	onOk: () => {
        // 		let curBtnId = getBtnsId('重新提交')
        // 		sessionStorage.setItem('buttonId', curBtnId)
        // 		let data = {
        // 			uuids: row.uuid
        // 		}
        // 		// 开始请求商品列表
        // 		ApiRequest(
        // 			this.requestApi.reAudit.url,
        // 			this.requestApi.reAudit.type,
        // 			data, true
        // 		).then(res => {
        // 			if (res.retStatus === '1') {
        // 				this.$Message.success('提交成功')
        // 				this.actionsChange()
        // 			}
        // 		})
        // 	}
        // })
      }
    }
  }
};
</script>
